﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQuery MiniUI - 专业WebUI控件库</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="keywords" content="jquery,web,grid,表格,datagrid,js,javascript,ajax,web开发,tree,table" />   
    <meta name="description" content="jQuery MiniUI - 专业WebUI控件库。它能缩短开发时间，减少代码量，使开发者更专注于业务和服务端，轻松实现界面开发，带来绝佳的用户体验。" />
    <link href="../core.css" rel="stylesheet" type="text/css" />
    
    <link href="common.css" rel="stylesheet" type="text/css" />
</head>
<body>

    <div class="header">
        <div class="headerInner">
            <a class="logo" href="http://www.miniui.com" title="jQuery MiniUI - 专业WebUI控件库">jQuery MiniUI</a>
            <a id="why" href="/why">为什么选择MiniUI？</a>

            <ul class="topmenu">
                <li><a href="/"><span>首页</span></a></li>
                <li onmouseover="showMenu('popup1', this)" onmouseout="hideMenu('popup1', this)"><a href="/product"><span>产品</span></a>
                    <ul id="popup1" class="popupmenu">
                        <li class="product"><a href="/product">产品介绍</a></li>
                        <li><a href="/features">功能特性</a></li>
                        <li><a href="/screenshots">界面截图</a></li>                        
                        <li><a href="/support">支持服务</a></li>
                        <li><a href="/license">授权方式</a></li>
                        
                        <li class="faq"><a href="/faq">常见问题</a></li>
                    </ul>
                </li>
                <li><a href="/demo"><span>示例</span></a></li>
                <li onmouseover="showMenu('popup2', this)" onmouseout="hideMenu('popup2', this)"><a href="/docs"><span>文档</span></a>
                    <ul id="popup2" class="popupmenu">                        
                        <li id="start_link"><a href="/docs/quickstart">快速入门</a></li>
                        <li><a href="/docs/tutorial">开发教程</a></li>
                        <li id="kb_link"><a href="/docs/kb">精华文章</a></li>
                        <li><a href="/docs/api">Api参考手册</a></li>
                    </ul>
                </li>
                <li><a href="/bbs"><span>论坛</span></a></li><li><a href="/download"><span>下载</span></a></li>
                
                <li><a href="/contact"><span>联系</span></a></li>
            </ul>
        
     
        </div>
    </div>
    <div class="topnav">
        <div class="topnavInner">
            <a href="/">首页</a>><a href="/docs">文档中心</a>><a href="/docs/tutorial">开发教程</a>><span>数据表格</span>
        </div>
    </div>
    <div class="body " >
        <div class="bodyInner">
            
        <div class="contentView">
            <h3>数据表格</h3>
            
            <a title="DataGrid 数据表格" href="../../demo/datagrid/datagrid.html" target="_blank"><img src="../api/images/datagrid.gif" /></a>

            <br /><br />
            <p class="p_demo"><span class="note">参考示例</span>：<a href="../../demo/datagrid/datagrid.html" target="_blank">数据表格</a>&nbsp;&nbsp;&nbsp; <a href="../../demo/datagrid/pager.html" target="_blank">分页表格</a></p>
            <br />

            <h4>一：创建表格</h4>
<pre class="code"><span style="color:blue">&lt;</span><span style="color:maroon">div </span><span style="color:red">id</span><span style="color:blue">="datagrid1" </span><span style="color:red">class</span><span style="color:blue">="mini-datagrid" </span><span style="color:red">style</span><span style="color:blue">="</span><span style="color:red">width</span><span style="color:blue">:700px;</span><span style="color:red">height</span><span style="color:blue">:280px;" 
    </span><span style="color:red">url</span><span style="color:blue">="../data/DataService.aspx?method=SearchEmployees"  </span><span style="color:red">idField</span><span style="color:blue">="id" </span><span style="color:red">allowResize</span><span style="color:blue">="true"
&gt;
    &lt;</span><span style="color:maroon">div </span><span style="color:red">property</span><span style="color:blue">="columns"&gt;
        &lt;</span><span style="color:maroon">div </span><span style="color:red">type</span><span style="color:blue">="indexcolumn" &gt;&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="loginname" </span><span style="color:red">width</span><span style="color:blue">="120" </span><span style="color:red">headerAlign</span><span style="color:blue">="center" </span><span style="color:red">allowSort</span><span style="color:blue">="true"&gt;</span>员工帐号<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;    
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="name" </span><span style="color:red">width</span><span style="color:blue">="120" </span><span style="color:red">headerAlign</span><span style="color:blue">="center" </span><span style="color:red">allowSort</span><span style="color:blue">="true"&gt;</span>姓名<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;                            
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="gender" </span><span style="color:red">width</span><span style="color:blue">="100" </span><span style="color:red">renderer</span><span style="color:blue">="onGenderRenderer" </span><span style="color:red">align</span><span style="color:blue">="center" </span><span style="color:red">headerAlign</span><span style="color:blue">="center"&gt;</span>性别<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="salary" </span><span style="color:red">width</span><span style="color:blue">="100" </span><span style="color:red">allowSort</span><span style="color:blue">="true"&gt;</span>薪资<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;                                    
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="age" </span><span style="color:red">width</span><span style="color:blue">="100" </span><span style="color:red">allowSort</span><span style="color:blue">="true"&gt;</span>年龄<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;
        &lt;</span><span style="color:maroon">div </span><span style="color:red">field</span><span style="color:blue">="createtime" </span><span style="color:red">width</span><span style="color:blue">="100" </span><span style="color:red">headerAlign</span><span style="color:blue">="center" </span><span style="color:red">dateFormat</span><span style="color:blue">="yyyy-MM-dd" </span><span style="color:red">allowSort</span><span style="color:blue">="true"&gt;</span>创建日期<span style="color:blue">&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;                
    &lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;
&lt;/</span><span style="color:maroon">div</span><span style="color:blue">&gt;   
</span></pre>
            


            <h4>二：数据加载</h4>
            <p>条件加载：</p>
<pre class="code"><span style="color:#006400">//从界面表单元素获取查询条件
</span>grid.load({
    name: document.getElementById(<span style="color:maroon">"key"</span>).value, 
    date: document.getElementById(<span style="color:maroon">"date"</span>).value
});
</pre>
            <p>分页导航：</p>
<pre class="code">grid.gotoPage(1, 10);   <span style="color: #006400">//跳转到第二页，每页20条数据
</span></pre>
            <p>字段排序：</p>
<pre class="code"><span style="color:#006400">//对"createtime"字段，进行降级排序
</span>grid.sortBy(<span style="color:maroon">"createtime"</span>, <span style="color:maroon">"desc"</span>);
</pre>
            <h4>三：服务端处理</h4>
<pre class="code"><span style="color:green">//查询条件
</span><span style="color:blue">string </span>key = Request[<span style="color:#a31515">"name"</span>];
<span style="color:green">//分页
</span><span style="color:blue">int </span>pageIndex = <span style="color:#2b91af">Convert</span>.ToInt32(Request[<span style="color:#a31515">"pageIndex"</span>]);
<span style="color:blue">int </span>pageSize = <span style="color:#2b91af">Convert</span>.ToInt32(Request[<span style="color:#a31515">"pageSize"</span>]);        
<span style="color:green">//字段排序
</span><span style="color:#2b91af">String </span>sortField = Request[<span style="color:#a31515">"sortField"</span>];
<span style="color:#2b91af">String </span>sortOrder = Request[<span style="color:#a31515">"sortOrder"</span>];

<span style="color:green">//数据库操作：使用查询条件、分页、排序等参数进行查询
</span><span style="color:#2b91af">Hashtable </span>result = SearchEmployees(key, pageIndex, pageSize, sortField, sortOrder);

<span style="color:green">//返回JSON：将查询的结果，序列化为JSON字符串返回        
</span><span style="color:#2b91af">String </span>json = PluSoft.Utils.<span style="color:#2b91af">JSON</span>.Encode(result);
Response.Write(json);
</pre>
            <h4>四：数据结构</h4>
            <p>在服务端处理后，获得的JSON结构如下：</p>         
<pre class="code">{
    total: 100,     <span style="color:#006400">//总记录数
     </span>data: [         <span style="color:#006400">//分页后的数组数据
         </span>{ ... },
        { ... },
        ...
    ]
}
</pre>

        </div>
            
        </div>
    </div>
    <div class="footer">
        <div class="footerInner">
            <div id="copyright">Copyright © 上海普加软件有限公司版权所有 </div>
            <div id="bottomlinks"><a href="/sitemap">网站导航</a>|<a href="/support">支持服务</a>|<a href="/license">授权方式</a>|<a href="/contact">联系我们</a></div>
        </div>
    </div>
</body>
</html>
